/**
 * 秒杀2.0js管理
 */

var _data, _i = 1, _n = 1, _m = 1, preDefault = 1;
$(function () {
    //添加活动
    $('.checkSubmit').click(function () {

        if (!preDefault) return !1;
        var cityFlag = true;
        var dataFlag = true;
        var timeFlag = true;
        var citylist = [];
        var _obj = $(this);
        var _data = {};
        if (!checkVailForm()) {
            return false;
        } else {
            _data = checkVailForm();
        }

        console.log(_data);

        //组合场次
        var _cityLength, _timeLength, _timesLength;

        _cityLength = _obj.parents('.Jactadd').find('.CitySelectInfo .picdemo').length; //城市
        _timeLength = _obj.parents('.Jactadd').find('.Timeslot .TimeSoltInfo').length;  //日期段
        _timesLength = _obj.parents('.Jactadd').find('.timeTimeslot .TimeSoltTimesInfo').length;


        if (_cityLength < 1) {
            standardTips('请添加城市');
            return false;
        }
        if (_timeLength < 1) {
            standardTips('请添加日期');
            return false;
        }
        if (_timesLength < 1) {
            standardTips('请添加场次时间');
            return false;
        }


        //城市
        $('input.cityinput').each(function (i, e) {
            if ($(e).val() == '') {
                standardTips('城市不能为空');
                cityFlag = false;
                return false;
            }
            citylist.push($(e).val())
        });


        //日期
        var timeRange = [];
        var dateRange = [];

        $('input.starttime').each(function (j, c) {

            if ($(c).val() == '') {
                standardTips('日期不能为空');
                dataFlag = false;
                return false;
            }

            var dateInfo = $(c).val();

            var preg = /^(\d{4})-(\d{2})-(\d{2})$/;

            if (!preg.test(dateInfo)) {

                standardTips('日期格式不正确');
                dataFlag = false;
                return false;

            }

            var startTime = $(c).val().replace(/\-/g, '');


            dateRange.push(startTime);
            dateRange.sort();
        })


        //时间段
        $('input.startplaytimes').each(function (j, k) {

            if ($(k).val() == '' || $('input.endplaytimes:eq(' + j + ')').val() == '') {
                standardTips('时间段不能为空');
                timeFlag = false;
                return false;
            }

            var strTime = $(k).val();
            var enTime = $('input.endplaytimes:eq(' + j + ')').val();
            var pregtime = /^(\d{2}):(\d{2})$/;

            if (!pregtime.test(strTime) || !pregtime.test(enTime)) {

                standardTips('时间格式不正确');
                timeFlag = false;
                return false;

            }

            var startpaly = $(k).val().replace(/\:/g, '') + '00';
            var endplay = $('input.endplaytimes:eq(' + j + ')').val().replace(/\:/g, '') + '00';


            if (parseInt(startpaly) >= parseInt(endplay)) {
                standardTips('开始时间不能大于等于结束时间');
                timeFlag = false;
                return false;
            }

            timeRange.push([startpaly, endplay]);

            timeRange.sort();

        })


        _data.timeRange = JSON.stringify(timeRange);
        _data.dateRange = JSON.stringify(dateRange);
        _data.citylist = JSON.stringify(citylist);

        if (!cityFlag || !dataFlag || !timeFlag) {

            return false;
        }

        preDefault = 0;
        $.post(addacturl, _data, function (data) {
            console.log(data);
            if (data.errno == 0) {
                standardTips('添加成功', 2);
                window.location.href = editacturl + "&ActivityID=" + data.data.Activity.ActivityID;
            } else {
                standardTips('添加失败', 2);
            }
        }, 'json')
    })


    //加载更多
    var page = 2;
    $('.JMoreActivity').click(function () {
        var _html = '';
        $.ajax({
            url: getMoreActicityUrlInfo,
            type: 'post',
            data: {Page: page},
            timeout: 15000,
            dataType: "json",
            beforeSend: function (XMLHttpRequest) {
                $(".JMoreActivity").html("加载中……");
            },
            success: function (data, textStatus) {
                console.log(data);
                if (data.errno == 0) {
                    if (data.data.list.length > 0) {
                        $.each(data.data.list, function (key, val) {

                            console.log(val.City.length);

                            _html += '<tr>' +
                                '<td><input type="checkbox" data-id="' + val.ActivityID + '"></td>' +
                                '<td class="act-name">' + val.attr.PageTitle + '<a class="act-view" href="' + getViewUrl + '&ActivityID=' + val.ActivityID + '"></a></td>' +
                                '<td>' + val.ID + '</td>' +
                                '<td>' + val.type.SubName + '</td>' +
                                '<td>' + val.Time + '</td>' +
                                '<td> ' + val.UrlTotal + '个链接 <a href="javasctipt:void(0)" class="Jcopy" data-href="">（查看链接）</a>';

                            $.each(val.City, function (i, e) {
                                _html += ' <input type="hidden" value="' + i + ':' + e + '" class="hidUrl">';
                            })


                            _html += '</td>';
                            _html += '</tr>';
                        })
                        $('.Joperate tbody').append(_html);
                        $(".JMoreActivity").html("加载更多秒杀活动");
                    } else {
                        $('.JMoreActivity').text('没有更多数据……');
                    }

                }
            },
            complete: function (XMLHttpRequest, textStatus) {
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $(".JMoreActivity").html('加载失败,<a href="#" class="JMoreActivity">点击重试</a>');
            }
        });
        page++;
    });


    //添加奖品类型
    $('.JsavePrize').click(function () {
        var _type;
        _type = $('.addpricebigborder').find('a').data('pictype');
        if (!_type) {
            standardTips('请选择奖品展示类型');
            return false;
        }
        console.log(_type);
        $('.prizetype').val(_type);
        $('#closePushPrizeBtn').trigger('click');

    })

    //添加奖品
    var d = 1;
    var dnum = $('.busnum').text();
    if (dnum == 0) {
        d = 1;
    } else {
        d = parseInt(dnum) + 1;
    }
    $('.Jaddvisit').click(function () {
        var _type, _html = '';
        //展示类型存在，不显示弹出框
        _type = $('.prizetype').val();
        //添加，展示添加的数据
        _html += '<div class="prize-info"> <div class="Jcitygarbinfo"> ' +
            '<div class="del-play"><a href="javascript:;">删除</a></div> ' +
            '<div class="control-group"> ' +
            '<label class="control-label ">奖品标题：</label> ' +
            '<div class="controls"> <input type="text" name="prize_name" class="prize_name"> </div> </div>' +
            ' <div class="control-group">' +
            '<label class="control-label prize-icon">奖品图片：</label> ' +
            '<div class="controls"> ' +
            '<div id="coverImgInfo">' +
            '<form id="imgForm" action="' + ajaxPicInfo + '" method="post" enctype="multipart/form-data">' +
            '<input type="file" id="coverImg" name="coverImg" accept="image/*" onChange="coverImgChange(this);">' +
            '<span id="coverShopImg"></span></form>' +
            '<input type="hidden" name="ShopPic" class="shoppic" id="shoppic"></div>' +
            '</div> </div> ' +
            '<div class="control-group dist-height"> ' +
            '<label class="control-label">试用分店：</label>' +
            '<div class="controls"> ' +
            '<input name="branchshop" class="branch-shop" placeholder="输入优惠券id"/>' +
            '<div class="dist-info"><a class="btn btn-danger Jdist">识别</a></div>' +
            '</div>' +
            '</div> ' +

            '<div class="control-group"> ' +
            '<label class="control-label"></label>' +
            '<div class="list-group dist-list">' +
            '</div> ' +
            '</div>';

        //<!--其他-->
        _html += '<div class="control-group"> ' +
            '<label class="control-label ">使用须知：</label> ' +
            '<div class="controls"><textarea class="fontContent" rows="10" cols="30"></textarea> </div> </div>';

        _html += '<div class="control-group"> ' +
            '<label class="control-label ">商家介绍：</label> ' +
            '<div class="controls"><textarea class="shopIntro" rows="10" cols="30"></textarea> </div> </div>';

        _html += '</div></div>';
        $('.prizeinfores').prepend(_html);
        $('.busnum').text(d);
        d++;
        console.log(d);


    })


    //删除奖品
    $('.prizeinfores').on('click', '.prize-info .del-play a', function () {
        var _obj = $(this), _num;
        standardConfirm('确定删除', function () {
            //删除节点
            _obj.parents('.prize-info').remove();

            //数量
            _num = $('.busnum').text();
            var _nu = _num - 1;

            $('.busnum').text(_nu);

            if (_nu == 0) {
                d = 1;
            } else {
                d = _nu + 1;
            }
        })

    })

    //识别分店id
    $('.prizeinfores').on('click', '.prize-info .Jdist', function () {
        var _obj = $(this), _branchid, _html = '', textval;
        _branchid = $.trim(_obj.parents('.prize-info').find('.branch-shop').val());
        if (!_branchid) {
            standardTips('请添加奖品id');
            return false;
        }

        $.post(ajaxGetBrach, {branchid: _branchid}, function (data) {

            console.log(data);

            if (data.data.list.length > 0) {
                $.each(data.data.list, function (i, n) {

                    _html += '<a href="#" class="list-item" data-city="' + n.City + '" data-shopid="' + n.ShopID + '">' + n.ShopName + '</a>';

                })

                _obj.parents('.prize-info').find('.dist-list').html(_html);
                _obj.parents('.prize-info').find('.dist-list').attr('couponName', data.couponName);
            } else {

                _html += '<a href="#">无法识别的分店id</a>';
                _obj.parents('.prize-info').find('.dist-list').html(_html);
                _obj.parents('.prize-info').find('.dist-list').attr('');
            }

        }, 'json')

    })

    //<input type="text" name="fontName" class="fontName">

    //添加奖品字段弹出参数传递
    $('.prizeinfores').on('click', '.prize-info .Jaddprize', function () {
        var _obj = $(this), _html = '';

        _html += '<div class="control-group font-group-res"> ' +
            '<div class="fontfield">' +
            '<span class="fieldname">添加奖品字段</span>' +
            '</div>' +
            '<div class="fontinput">' +
            '<div>' +
            '<select name="fontName">' +
            '<option value="使用须知">使用须知</option>' +
            '<option value="商家介绍">商家介绍</option>' +
            '</select>' +
            '</div>' +
            '<div><textarea class="fontContent" rows="10" cols="30"></textarea>' +
            '<a href="javascript:void(0)"><img src=' + RESOURCE_URL + '/images/del.png></a>' +
            '</div></div>' +

            '</div>';
        _obj.parents('.prize-info').find('.prize-deatillist').append(_html);

        console.log(111);
    })

    //删除添加字段
    $('.prizeinfores').on('click', '.prize-info .prize-deatillist img', function () {
        var _obj = $(this);
        standardConfirm('确定删除', function () {
            //删除节点
            _obj.parents('.font-group-res').remove();
        })

    })


    //添加字段

    $('.JsaveFontInfo').click(function (e) {
        var _html = '', _obj;
        var fontName = $('.fontName').val();
        _obj = $('.fontObj').val();
        console.log(_obj);
        if (!checkName(fontName)) {
            standardTips('填写字段名');
            return false;
        }
        var fontContent = $('.fontContent').val();
        if (!checkName(fontContent)) {
            standardTips('填写字段内容');
            return false;
        }

        _html += '<div class="controls"><span class="prize-detail"><i class="prizefontname">' + fontName + '</i>/<i class="prizefontcontent">' + fontContent +
            '</i>（<a href="#" class="del-prize">删除</a> . <a href="#" class="edit-prize">编辑</a>）</span> ' +
            '</div>';

        $('#closePushPrizedetailBtn').trigger('click');
        $('.fontName').val('');
        $('.fontContent').val('');
        _obj.parents('.prize-info').find('.prize-deatillist').append(_html);
    })


    //添加场次城市
    $('.JactivityTotal').on('click', '.addVisit', function () {
        console.log(123);
        var _obj = $(this), _html = '';
        m++;
        _html += '<span class="picdemo"> <input type="text" class="cityinput" id="citySelect' + m + '" placeholder="请输入城市"> ' +
            '<a href="javascript:void(0)"><img src="/public/images/del.png"></a></span>';
        _obj.parents('.Jmanyactivity').find('.CitySelectInfo').append(_html);
        new Vcity.CitySelector({input: 'citySelect' + m});

    })


    //删除场次城市
    $('.JactivityTotal').on('click', '.CitySelectInfo .picdemo img', function () {
        console.log(111);
        var _obj = $(this);
        standardConfirm('删除城市，将删除该城市相关所有时段活动场次，确认删除？', function () {
            //删除节点
            _obj.parents('.picdemo').remove();
        })
    })


    //添加场次活动时间段
    $('.JactivityTotal').on('click', '.addTime', function () {
        // console.log(1234);
        var _obj = $(this), _html = '', _time = "laydate({format: 'YYYY-MM-DD'})";
        _html += '<div class="controls TimeSoltInfo">' +
            '<input type="text" name="ExpirationTime" class="starttime" placeholder="请选择日期" onclick="' + _time + '">' +
            ' <a href="javascript:void(0)"><img src="/public/images/del.png"></a> </div>';

        _obj.parents('.Jmanyactivity').find('.Timeslot').append(_html);
    })

    //添加场次活动场次时间段
    var k = 1, p;

    var playNum = $('.playnuminfo').text();
    if (playNum == 0) {
        p = 1;
    } else {
        p = parseInt(playNum) + 1;
    }

    console.log(p);
    $('.JactivityTotal').on('click', '.addTimesTime', function () {
        var _obj = $(this), _html = '';
        _html += '<div class="controls TimeSoltTimesInfo">' +
            '<input type="text" name="ExpirationTime" class="startplaytimes starttimestime' + k + '" placeholder="请选择开始时间" value="" data-autoclose="true">' +
            ' 至 ' +
            '<input type="text" name="ExpirationTime" class="endplaytimes endtimestime' + k + '" placeholder="请选择结束时间" value="" data-autoclose="true">' +
            ' <a href="javascript:void(0)"><img src="/public/images/del.png"></a> </div>';
        _obj.parents('.Jmanyactivity').find('.timeTimeslot').append(_html);

        $('.starttimestime' + k).clockpicker();
        $('.endtimestime' + k).clockpicker();
        $('.playnuminfo').text(p);
        p++;
        k++;
    })

    //删除场次时间段
    var a = 0
    $('.JactivityTotal').on('click', '.TimeSoltTimesInfo img', function () {
        var _obj = $(this);
        standardConfirm('删除时段，将删除该该时段相关所有城市活动场次，确认删除？', function () {
            //删除节点
            var num = $('.playnuminfo').text();
            _obj.parents('.TimeSoltTimesInfo').remove();
            num = num - 1;
            $('.playnuminfo').text(num);
            if (num == 0) {
                p = 1;
            } else {
                p = num + 1;
            }

        })

    })

    //删除场次添加字段
    $('.JactivityTotal').on('click', '.Timeslot img', function () {
        var _obj = $(this);
        standardConfirm('删除时段，将删除该该时段相关所有城市活动场次，确认删除？', function () {
            //删除节点
            _obj.parents('.TimeSoltInfo').remove();
        })

    })


    //添加活动场次添加奖品
    $('.JactivityTotal').on('click', '.JeditaddPrize', function () {
        var _obj = $(this), _html = '';

        _html += '<div class="editPrizelist"> ' +
            '<input type="text" name="name" placeholder="奖品id" class="prizeid"> ' +
            '<input type="text" name="name" class="prize-number" placeholder="数量" class="prizemun"> ' +
            '<a href="javascript:void(0)"><img src="/public/images/del.png"></a>' +
            '<span class="couponNameInfo" pid="1"></span>' +
            ' </div>';
        _obj.parents('.editaddprizelist').find('.editActivityPrizeList').append(_html);
    })

    //删除活动场次添加奖品
    $('.JactivityTotal').on('click', '.editPrizelist a', function () {
        var _obj = $(this);
        standardConfirm('确定删除', function () {
            //删除节点
            _obj.parents('.editPrizelist').remove();
        })
    })

    //控制键盘输入奖品id和数量

    $('.JactivityTotal').on('keyup', '.editActivityPrizeList .editPrizelist input', function () {
        $(this).val($(this).val().replace(/[^0-9.]/g, ''));
    })

    $('.JactivityTotal').on('blur', '.editActivityPrizeList .editPrizelist .prizeid', function () {
        var obj = $(this);
        var couponID = obj.val();
        console.log(couponID);
        $.post(getBranchName, {couponID: couponID}, function (data) {
            console.log(data);
            if (data.coupon_name) {
                obj.parents('.editPrizelist').find('.couponNameInfo').text(data.coupon_name);
                obj.parents('.editPrizelist').find('.couponNameInfo').attr('pid', '1');

            } else {
                obj.parents('.editPrizelist').find('.couponNameInfo').text('奖品ID不存在');
                obj.parents('.editPrizelist').find('.couponNameInfo').attr('pid', '0');

            }


        }, 'json')


    })

    //提交场次
    $('.JaddPlayCity').click(function () {

        if (!preDefault) return !1;

        var gift = {};
        var citylist = [];
        var prizename = [];
        var icon = [];
        var field = [];
        var intro = [];
        var flagPlay = true;
        var timePlay = true;
        var couPonPlay = true;
        var shopCoupon = [];
        var couponName = [];
        var giftid = [];

        var ActivityID = $('.ActivityID').val();
        var AttributeID = $('.AttributeID').val();
        var cityID = $('.CityIDInfo').val();
        var type = $('input[type=radio]:checked').val();

        var length = $('.prizeinfores').find('.prize-info').length;
        if (!length) {
            standardTips('请添加奖品信息');
            return false;
        }

        $('.prizeinfores .prize-info').each(function (a, b) {

            giftid.push($(b).find('.del-play').data('giftid'));


            if ($(b).find('.prize_name').val() == '') {
                standardTips('名称不能为空');
                flagPlay = false;
                return false;
            }
            prizename.push($(b).find('.prize_name').val());


            if ($(b).find('.shoppic').val() == '') {
                standardTips('奖品图片不能为空');
                flagPlay = false;
                return false;
            }

            icon.push($(b).find('.shoppic').val());

            //卡券试用门店
            shopCoupon[a] = [];

            console.log($(b).find('.dist-list .list-item').length);
            if (!$(b).find('.dist-list .list-item').length) {
                standardTips('请输入优惠券id');
                flagPlay = false;
                return false;
            }

            $(b).find('.dist-list .list-item').each(function (q, w) {

                shopCoupon[a].push($(w).data('shopid'));
                shopCoupon[a].push($(w).text());
            })

            //奖品详情

            if ($(b).find('.fontContent').val() == '') {
                standardTips('使用须知不能为空');
                flagPlay = false;
                return false;
            }

            if ($(b).find('.shopIntro').val() == '') {
                standardTips('商家介绍不能为空');
                flagPlay = false;
                return false;
            }

            field.push($(b).find('.fontContent').val());
            intro.push($(b).find('.shopIntro').val());

        })


        if (!flagPlay) {
            return false;
        }


        //添加
        $('div.Jmanyactivityinfo').each(function (i, target) {

            var timeID = $(target).find('.goods-list').data('timeid');
            var date = $(target).find('.goods-list').data('date');
            if (!gift[date]) gift[date] = [];
            if (!gift[date][timeID]) gift[date][timeID] = [];

            //if(!$('.date-'+date).find('input').length){
            //    standardTips('每个日期至少有一个奖品');
            //    timePlay = false
            //    return false;
            //
            //}

            var timesLength = $(target).find('.editActivityPrizeList .editPrizelist').length;

            if (!timesLength) {
                standardTips('请填写奖品');
                timePlay = false
                return false;
            }

            $(target).find('input.prizeid').each(function (n, e) {
                var stack = {};

                if ($(e).val() == '') {
                    standardTips('请填写奖品');
                    couPonPlay = false;
                    return false;
                }

                stack.couponid = parseInt($(e).val());
                stack.couponlistid = $(e).data('couponlistid');

                if ($(target).find('input.prize-number:eq(' + n + ')').val() == '' || $(target).find('input.prize-number:eq(' + n + ')').val() == 0) {
                    standardTips('请填写数量');
                    couPonPlay = false;
                    return false;
                }

                if ($(target).find('.couponNameInfo:eq(' + n + ')').attr('pid') == '0') {

                    standardTips('奖品ID不存在');
                    couPonPlay = false;
                    return false;

                }


                stack.amount = $(target).find('input.prize-number:eq(' + n + ')').val();
                stack.couponName = $(target).find('.couponNameInfo:eq(' + n + ')').text();
                gift[date][timeID].push(stack);
            });

        });

        console.log(gift);

        if (!timePlay) {
            return false;
        }

        if (!couPonPlay) {
            return false;
        }

        var data = {
            type: type,
            cityID: cityID,
            giftid: giftid,
            prizename: prizename,
            icon: icon,
            shopCoupon: shopCoupon,
            field: field,
            intro:intro,
            ActivityID: ActivityID,
            AttributeID: AttributeID,
            gift: JSON.stringify(gift),
            couponName: couponName
        };

        preDefault = 0;

        $.post(ajaxAddHandel, data, function (data) {
            console.log(data)
            if (data.errno == 0) {
                standardTips('编辑成功', 2);
                window.location.href = editacturl + "&ActivityID=" + data.data.Activity.ActivityID;
            } else {
                standardTips('编辑失败', 2);
            }
        }, 'json')
    })


    //活动详情页编辑提示
    $('.editSubmit').click(function () {
        var _obj = $(this);
        standardActivityConfirm('城市和时段场次信息将丢失，保存后请重新编辑场次信息', function () {

            if (!preDefault) return !1;

            var citylist = [];
            var _data = {};
            var cityFlag = true;


            var _Name, _Pic, _Desc, _prizeLimit;

            _Name = $('input[name=Name]').val();
            if (!checkName(_Name)) {
                standardTips('填写活动标题');
                return false;
            }

            _Desc = $('.Businessdesc').val();
            if (!_Desc) {
                standardTips('填写活动说明');
                return false;
            }

            _prizeLimit = $("input[name='prizeLimit']").val();

            if (!_prizeLimit) {
                standardTips('奖品数量限制不能为空');
                return false;
            }

            _data = {
                Name: _Name,
                Desc: _Desc,
                prizeLimit: _prizeLimit
            };

            var ActivityID = $('.ActivityID').val();

            _data.ActivityID = ActivityID;

            $.post(editGraburl, _data, function (data) {
                console.log(data);
                if (data.errno == 0) {
                    standardTips('编辑成功', 2);
                    window.location.href = editacturl + "&ActivityID=" + data.data.Activity.ActivityID;
                } else {
                    standardTips('添加失败', 2);
                }
            }, 'json')
        })
    })

    //编辑活动


    ////首页列表查看
    $(".Joperate tbody").on('mouseenter', 'tr', function () {
        var html = '<span class="Jview" title="查看">查看</span>';
        $(this).find(".act-view").html(html);
    });

    $(".Joperate tbody").on('mouseleave', 'tr', function () {
        $(this).find(".act-view").html('');
    });

    //详情页，点击更新加载上传按钮
    $('.updateSite').click(function () {
        var _html = '';
        _html += '<br/>' +
            '<div id="packageInfo">' +
            '<form id="packageForm" action="' + uploadifyUrl + '" method="post" enctype="multipart/form-data">' +
            '<input type="file" id="packageupload" name="coverImg" onchange="upfilePackage(this)"></form>' +
            '<span class="form-required uploadStatus"></span>' +
            '<input type="hidden" name="packageName" id="image" class="image">' +
            '</div>';

        $('.packageList').html(_html);
        $('.packageOne').hide();
    })


    //复制链接
    $('.Joperate').on('click', '.Jcopy', function () {
        var _url = '';
        $(this).parents('tr').find('.hidUrl').each(function (i, e) {
            _url += $(e).val() + '<br/>';
        })
        console.log(_url);
        standardAllow(_url, function () {

        });
    })


    //活动详情页编辑提示
    $('.Jact-edit a').click(function () {
        var activity = $('.act_all').data('activity');
        standardActivityConfirm('编辑活动信息前，请确保活动下线。', function () {
            window.location.href = editUrl + "&ActivityID=" + activity;
        });
    })

    $('.Jactivity-view').on('click', 'em', function () {
        var AttributeID = $(this).data('attribu');
        var CityID = $(this).data('city');
        var ActivityID = $(this).data('activi');
        standardActivityConfirm('编辑活动信息前，请确保活动下线。', function () {
            window.location.href = editPlayUrl + '&ActivityID=' + ActivityID + '&CityID=' + CityID + '&AttributeID=' + AttributeID;
        });
    })

})

function checkVailForm() {
    var _Name, _Pic, _Desc, _prizeLimit;

    _Name = $('input[name=Name]').val();
    if (!checkName(_Name)) {
        standardTips('填写活动标题');
        return false;
    }

    _Desc = $('.Businessdesc').val();
    if (!_Desc) {
        standardTips('填写活动说明');
        return false;
    }

    _prizeLimit = $("input[name='prizeLimit']").val();

    if (!_prizeLimit) {
        standardTips('奖品数量限制不能为空');
        return false;
    }

    _data = {
        Name: _Name,
        Pic: _Pic,
        Desc: _Desc,
        prizeLimit: _prizeLimit
    };

    return _data;
}
/**
 *
 * @param obj
 */

function upfilePackage(obj) {
    var file = $(obj).val();
    if (!file) {
        return false;
    }
    $("#actimgForm").ajaxSubmit({
        dataType: 'json',
        beforeSend: function (XMLHttpRequest) {
            $("#coverActImg").html("上传中……");
        },
        success: function (data) {
            console.log(data);
            $("#coverActImg").html("<a href='" + data + "' target='_blank'>预览</a>");
            $(obj).parents('#actcoverImgInfo').find('.image').val(data);
            standardTips('上传成功！');

        }
    });
}


/**
 *编辑
 * @param obj
 */

function editUpfilePackage(obj) {

    var file = $(obj).val();
    if (!file) {
        return false;
    }
    $("#actimgForm").ajaxSubmit({
        dataType: 'json',
        beforeSend: function (XMLHttpRequest) {
            $("#coverActImg").html("上传中……");
        },
        success: function (data) {
            console.log(data);
            if (data.errno == 0) {
                $("#coverActImg").html("<a href='" + data.data.AlbumInfo.BgUrl + "' target='_blank'>预览</a>");
                $(obj).parents('#actcoverImgInfo').find('.grabPic a').attr('href', data.data.AlbumInfo.BgUrl);
                $(obj).parents('#actcoverImgInfo').find('.grabPic img').attr('src', data.data.AlbumInfo.BgUrl);
                $(obj).parents('#actcoverImgInfo').find('.image').val(data.data.AlbumInfo.BgUrl);
                $(obj).parents('#actcoverImgInfo').find('.image').attr('albumid', data.data.AlbumInfo.AlbumID);
                standardTips('上传成功！');
            } else {
                alert(data.error);
            }
        }
    });
}


/**
 * 检测名称是否完全
 * @param name
 * @returns {boolean}
 */
function checkName(name) {
    var _parmName, checkName;
    _parmName = $.trim(name);
    checkName = /^.{1,}$/;
    if (!checkName.test(_parmName)) {
        return false;
    }
    return true;
}



